package com.hzqy.web.ac.epg;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.service.epg.AcProductService;
import com.hzqy.web.vo.epg.ActivityProductVo;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/acProduct")
public class AcProductAction {
    @Resource
	private AcProductService serviceAction;
    
	@RequestMapping("/acProductUpdateAc")
	@ResponseBody
	public Object acProductUpdateAc(ActivityProductVo aaVo,String startdate, String enddate){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		if (startdate!=null && startdate!="") {
			aaVo.setF_ap_startdate(startdate);
		}
		if (enddate!=null && enddate!="") {
			aaVo.setF_ap_enddate(enddate);
		}
		int i=serviceAction.updateAc(aaVo);
		if(i > 0){
			resultMap.put("success", true);
			resultMap.put("result", "修改成功!");
		} else {
			resultMap.put("success", true);
			resultMap.put("result", "修改失败!flag=" + i);
		}
		return resultMap;
	}
	@RequestMapping("/acProductSelectByReq")
	@ResponseBody
	public Object acProductSelectByReq(ActivityProductVo aaVo){
		return serviceAction.selectById(aaVo);
	}
    @RequestMapping("/acProductSelect")
	@ResponseBody
	public Object acProductSelect(String f_ap_name){
		if(f_ap_name!=null){
			ActivityProductVo aaVo=new ActivityProductVo();
			aaVo.setF_ap_name(f_ap_name);
			return serviceAction.selectByReq(aaVo);
		}else {
			 Map<String, Object> map=new HashMap<String, Object>();
			 map.put("maxResults",10);
			 map.put("minResult",5);
			return serviceAction.selectAc(map);
		}
	}
	@RequestMapping("/acProductDelete")
	@ResponseBody
	public Object acProductDelete(ActivityProductVo aaVo){
		aaVo.setF_ap_id(12);
		DateFormat dateFormat=new SimpleDateFormat();
		dateFormat.format(aaVo.getF_ap_startdate());
		return serviceAction.deleteAc(aaVo);
	}
	@RequestMapping("/acProductInsert")
	@ResponseBody
	public Object acProducInsert(ActivityProductVo aaVo, String startdate, String enddate) {
		if (startdate!=null || startdate!="") {
			aaVo.setF_ap_startdate(startdate);
		}
		if (enddate!=null || enddate!="") {
			aaVo.setF_ap_enddate(enddate);
		}
		int i = serviceAction.insertAc(aaVo);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		if(i > 0){
			resultMap.put("success", true);
			resultMap.put("result", "新增成功!");
		} else {
			resultMap.put("success", true);
			resultMap.put("result", "新增失败!flag=" + i);
		}
		return resultMap;
	}
}
